(setq *small-rules* '(

(=> (and (p ?p) (q ?q))
 (x ?p ?q))
(=> (and (r ?r) (s ?s))
 (y ?r ?s))
(=> (and (x ?x1 ?x2) (y ?y1 ?y2))
 (z ?x1 ?y1))

))

(setq *ex* '((p p1) (q q1) (r r1) (s s1)))

;; initialize a new test case based on the 
;; plan recognition example from Ng's thesis.
(defun test-sm (bc-only? focused? probability steps 
		&optional (example *ex*) (pick-belief #'pick-belief-random)) 
  (initialize)
  ;; for plan recognition, we're basically following a single narrative.
  (add-sensor 'story wm)

  ;; build long-term memory.
  (dolist (r *small-rules*) (store-rule r kb))
  ;; (dolist (r *sort-hierarchy*) (store-rule r kb))

  (add-facts example 'story wm)

  (dotimes (i steps) (infer wm kb :bc-only? bc-only? 
			    :focused? focused? :p probability 
			    :pick-belief pick-belief))


  (format t "~%Observations:~%")
  (dolist (i (get-observed-beliefs (wm-prime wm)))
    (format t "~T~A~%" (second i)))

  (format t "Assumptions:~%")
  (dolist (i (get-local-beliefs (wm-prime wm)))
    (format t "~T~A~%" (second i)))

  (dolist (i (get-justifications (wm-prime wm)))
    (format t "~%~%~A supports: ~A" (justification-id i) 
	    (sort (mapcar #'(lambda (x) (belief-id (second x))) (get-supported-beliefs i (wm-prime wm)))
		  #'string< :key #'symbol-name))
        (pprint  i))

  (output-dot wm))

(defun inc-test-sm (bc-only? focused? probability steps &optional (example *ex*) 
		    (plot? t) (pick-belief #'pick-belief-random)) 

  (initialize)

  ;; for plan recognition, we're basically following a single narrative.
  (add-sensor 'story wm)

  ;; build long-term memory.
  (dolist (r *small-rules*) (store-rule r kb))
  ;; (dolist (r *sort-hierarchy*) (store-rule r kb))

  (add-facts (list (car example)) 'story wm)
  (dotimes (i steps) (infer wm kb :bc-only? bc-only? 
			    :focused? focused? :p probability 
			    :pick-belief pick-belief))
  
  (dolist (f (cdr example))
    (add-facts (list f) 'story wm)
    (dotimes (i steps) (infer wm kb :bc-only? bc-only? 
			    :focused? focused? :p probability 
			    :pick-belief pick-belief))
    (when plot?
      (output-dot wm)
      (sleep 1))))
